package com.heima.model.common.dtos;

import com.heima.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel
public class ResponseResult<T> implements Serializable {
    @ApiModelProperty(value = "响应状态码", required = true, example = "5000")
    private Integer code;
    @ApiModelProperty(value = "响应信息", required = false, example = "用户名或密码错误")
    private String message;
    @ApiModelProperty(value = "成功响应信息", required = false, example = "操作成功")
    private T data;

    /**
     * 服务器端处理成功
     * @return
     * @param <T>
     */
    public static <T> ResponseResult success() {
        return new ResponseResult(AppHttpCodeEnum.SUCCESS.getCode(), AppHttpCodeEnum.SUCCESS.getErrorMessage(), null);
    }

    /**
     * 服务器端处理成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> ResponseResult success(T data) {
        return new ResponseResult(AppHttpCodeEnum.SUCCESS.getCode(), AppHttpCodeEnum.SUCCESS.getErrorMessage(), data);
    }

    /**
     * 服务器端处理失败
     * @param appHttpCodeEnum
     * @return
     * @param <T>
     */
    public static <T> ResponseResult error(AppHttpCodeEnum appHttpCodeEnum) {
        return new ResponseResult(appHttpCodeEnum.getCode(), appHttpCodeEnum.getErrorMessage(), null);
    }
}
